package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.LoginInfo
import de.baumann.browser.api.net.vo.Rank
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IProPlanView
import de.baumann.browser.model.LicenceModel
import de.baumann.browser.model.UserModel
import de.baumann.browser.utils.*

class ProPlanPresenter : BasePresenter<IProPlanView>() {
    private val userModel = UserModel()
    fun getRank() {
        LicenceModel().licenceRank
                .subscribe(object : OdinObserver<List<Rank>>(view) {
                    override fun onSuccess(data: List<Rank>?) {
                        view?.setRanks(data)
                    }
                })
    }

    fun login() {
        userModel.login(getMoneyAddress(), "")
                .subscribe(object : OdinObserver<LoginInfo>(view) {
                    override fun onSuccess(loginInfo: LoginInfo) {
                        saveUser(loginInfo)
                        UnicornUtil.setUserInfo(loginInfo)
                        saveInviteCode(loginInfo.inviteCode)
                        saveInviteCodeStatus(loginInfo.inviteId)
                        saveFormAddress(loginInfo.fromAddress)
                        saveLogin(true)
                    }
                })
    }
}